package io.renren.modules.course.service.impl;

import io.renren.modules.oss.entity.MysqlOssEntity;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.course.dao.TeacherDao;
import io.renren.modules.course.entity.TeacherEntity;
import io.renren.modules.course.service.TeacherService;
import org.springframework.web.multipart.MultipartFile;


@Service("teacherService")
public class TeacherServiceImpl extends ServiceImpl<TeacherDao, TeacherEntity> implements TeacherService {

    @Autowired
    TeacherDao teacherDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<TeacherEntity> page = this.selectPage(
                new Query<TeacherEntity>(params).getPage(),
                new EntityWrapper<TeacherEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public Integer upload(Map<String, Object> file) {
        baseMapper.insertFile(file);
        Integer i = teacherDao.getImgIdByName((String) file.get("name"));
        return i;
    }

    @Override
    public MysqlOssEntity getImgByName(String name) {
        return baseMapper.getImgByName(name);
    }

    @Override
    public List  getTeacherList() {
        return teacherDao.getTeacherList();
    }

    @Override
    public void updateTeacherInfo(TeacherEntity teacher) {
        teacherDao.updateTeacherInfo(teacher);
    }

    /*@Override
    public Integer upload(MultipartFile file) {
        teacherDao.insertFile(file);
        INSERT INTO images
                (name,img)
        VALUES
                (#{name}, #{buffer,jdbcType=BLOB})
        return teacherDao.getNewImgId();
    }*/

}
